//
// Created by Semir on 2020/3/27.
//

#include <iostream>

using namespace std;

const int MAX_NUM = 35;

int num;
int inOrder[MAX_NUM];
long long point[MAX_NUM][MAX_NUM] = {0};
int root[MAX_NUM][MAX_NUM];

long long dfs(int left, int right) {
    if (left > right) {
        return 1;
    }
    if (left == right) {
        return inOrder[left];
    }
    if (point[left][right] != 0) {
        return point[left][right];
    }
    for (int i = left; i <= right; i++) {
        long long temp = dfs(left, i - 1) * dfs(i + 1, right) + inOrder[i];
        if (temp > point[left][right]) {
            root[left][right] = i;
            point[left][right] = temp;
        }
    }
    return point[left][right];
}

void recurPrint(int left, int right) {
    if (left > right) {
        return;
    }
    cout << root[left][right] + 1 << " ";
    recurPrint(left, root[left][right] - 1);
    recurPrint(root[left][right] + 1, right);
}

int main () {
    cin >> num;
    for (int i = 0; i < num; i++) {
        cin >> inOrder[i];
        root[i][i] = i;
        point[i][i] = i;
    }
    cout << dfs(0, num - 1) << endl;
    recurPrint(0, num - 1);
    return 0;
}